package com.wdcloud.netlibrary;

import com.wdcloud.netlibrary.platform.OkHttpPlatform;
import com.wdcloud.netlibrary.platform.Platform;
import com.wdcloud.netlibrary.request.IRequestBuild;

import java.util.Map;


public class NetHelper implements Platform {

    private Platform realPlatform;

    private NetHelper() {
        this.realPlatform = new OkHttpPlatform();
    }

    public static NetHelper getInstance() {
        return NetHelperHolder.sNetWorkManager;
    }


    private static class NetHelperHolder{
        private static final NetHelper sNetWorkManager = new NetHelper();
    }

    /**
     * 替换具体实现操作
     *
     * @param platform
     */
    public void setRealPlatform(Platform platform) {
        this.realPlatform = platform;
    }

    @Override
    public IRequestBuild doGet() {
        return this.realPlatform.doGet();
    }

    @Override
    public IRequestBuild doPost() {
        return this.realPlatform.doPost();
    }

    @Override
    public IRequestBuild doJsonPost() {
        return this.realPlatform.doJsonPost();
    }

    @Override
    public IRequestBuild doBytePost() {
        return this.realPlatform.doBytePost();
    }

    @Override
    public IRequestBuild doUploadFile() {
        return this.realPlatform.doUploadFile();
    }

    @Override
    public IRequestBuild downLoadFile() {
        return this.realPlatform.downLoadFile();
    }

    @Override
    public void cancel(Object o) {
        this.realPlatform.cancel(o);
    }

    @Override
    public void setProxy(Map<String, Object> map) {
        this.realPlatform.setProxy(map);
    }

    @Override
    public void setCookie(String key, String value) {
        this.realPlatform.setCookie(key, value);
    }
}